package gold.digger;

import gold.utils.InputUtil;

import java.util.*;
import java.util.List;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC849 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int maxDistToClosest(int[] seats) {
            TreeSet<Integer> set = new TreeSet<>();
            int prevOne = 0, cur = 0;
            while (prevOne < seats.length && seats[prevOne] == 0) ++prevOne;
            set.add(prevOne);

            cur = prevOne + 1;
            while (cur < seats.length) {
                if (seats[cur] == 1) {
                    int interval = (cur - prevOne) / 2;
                    set.add(interval);
                    prevOne = cur;
                }

                ++cur;
            }

            if (seats[seats.length - 1] == 0) set.add(seats.length - prevOne - 1);
            return set.last();
        }
    }

    public void run() {
        Solution solution = new Solution();
        int[] arr = InputUtil.toIntegerArray("[0,1]");
        System.out.println(solution.maxDistToClosest(arr));
    }

    public static void main(String[] args) throws Exception {
        LC849 an = new LC849();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
